package com.wpen.unit.config;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.context.annotation.Configuration;

import com.wpen.unit.core.RegistryScheduleWorker;

import lombok.extern.slf4j.Slf4j;

/**
 * 
 * 
 * @author Wang Peng
 * @date 2022-11-28
 */
@Configuration
@Slf4j
public class DrsJobInitialize implements InitializingBean, DisposableBean {
    private List<DisposableBean> listDaemonBeans = new ArrayList<>();

    @Override
    public void afterPropertiesSet() throws Exception {
        // 启动批次扫描线程
    	RegistryScheduleWorker registryScheduleWorker = RegistryScheduleWorker.getInstance();
        listDaemonBeans.add(registryScheduleWorker);
        registryScheduleWorker.start();
    }

    @Override
    public void destroy() throws Exception {
        if(listDaemonBeans != null) {
            for (DisposableBean disposableBean : listDaemonBeans) {
                disposableBean.destroy();
            }
        }
        log.info("ucp-job-agent bye..");
    }

}
